package light.mvc.service;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author laijianbo
 * 2014-7-3
 */
@Transactional
@SuppressWarnings("unchecked")
public abstract class ServiceImpl<T> {
	public Class<T> clazz;
	public ServiceImpl() {
		
		Type type = this.getClass().getGenericSuperclass();
		ParameterizedType parameterizedType = (ParameterizedType) type;
		Type[] types = parameterizedType.getActualTypeArguments();
		
		clazz = (Class<T>) types[0];
	}
	protected HibernateTemplate hibernateTemplate;
	
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	public DetachedCriteria getCriteria() {
		return DetachedCriteria.forClass(clazz);
	}
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	
}
